package com.masterrabbit.service;

import com.masterrabbit.domain.Packages;
import com.masterrabbit.domain.Services;
import com.masterrabbit.mapper.PackagesMapper;
import com.masterrabbit.mapper.ServicePackageMapper;
import com.masterrabbit.mapper.ServicesMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;
import java.util.List;

@Service
public class PackagesService {
    @Autowired
    private PackagesMapper packagesMapper;
    @Autowired
    private ServicePackageMapper servicePackageMapper;
    public List<Packages> searchPackages(Integer merchantId){
        List<Packages>  packages=packagesMapper.searchPackages(merchantId);
        for (Packages p:packages){
            System.out.println(p.getPackageId());
          List<Services>  services= servicePackageMapper.selectBypackage(p.getPackageId());
            BigDecimal sum= BigDecimal.valueOf(0);
            for (Services s:services){
                sum=s.getPrice().add(sum);
            }
            p.setPrince(sum);
            p.setServices(services);
        }
        return packages;
    }
}
